package leetcode.code017;

import java.util.ArrayList;
import java.util.List;

public class Solution extends Solution017 {

	char[][] table = new char[][] {
		{ '!', '@', '#' },
		{ 'a', 'b', 'c' },
		{ 'd', 'e', 'f' },
		{ 'g', 'h', 'i' },
		{ 'j', 'k', 'l' },
		{ 'm', 'n', 'o' },
		{ 'p', 'q', 'r', 's' },
		{ 't', 'u', 'v' },
		{ 'w', 'x', 'y', 'z' }, };

	@Override
	public List<String> letterCombinations(String digits) {
		List<String> ans = new ArrayList<>();
		if (digits != null && digits.length() != 0) {
			char[] arr = digits.toCharArray();
			StringBuffer temp = new StringBuffer();
			letterCombinations(arr, 0, temp, ans);
		}
		return ans;
	}

	private void letterCombinations(char[] arr, int index, StringBuffer temp, List<String> ans) {
		if (index == arr.length) {
			ans.add(temp.toString());
			return;
		}
		char num = arr[index];
		char[] chars = table[num - '1'];
		for (char c : chars) {
			temp.append(c);
			letterCombinations(arr, index + 1, temp, ans);
			temp.deleteCharAt(temp.length() - 1);
		}
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();

	}

}
